<!--
 * @Author: AFun
-->
<template>
  <van-pagination :ref="info._id" v-model="currentPage" v-ui-ref="vSetRef" mode="simple" :page-count="pageData.length" @change="handleCurrentChange">
    <template #prev-text>
      {{ '<<' }}
    </template>
    <template #next-text>
      {{ '>>' }}
    </template>
  </van-pagination>
</template>
<script>
  import { defineComponent } from 'vue'
  import { Pagination } from 'vant'
  // import isArray from 'lodash/isArray'
  // import merge from 'lodash/merge'
  // import trim from 'lodash/trim'
  // import request from '@/utils/request'
  // import { GFCD } from '@/utils/utils'
  // import isEmpty from 'lodash/isEmpty'
  import { UiMixin, RefsInjectMixin } from '@ve/mixin'
  // import { processingConstant, replaseRegVariable } from '@ve/utils/utils'

  export default defineComponent({
    name: 'UiPdaPagination',
    components: { [Pagination.name]: Pagination },

    mixins: [UiMixin, RefsInjectMixin],
    data() {
      return {
        currentPage: 1,
        pageData: [],
      }
    },
    computed: {
      formDataPage() {
        return this.info.data?.formData
      },
    },
    watch: {
      //
      formDataPage: {
        handler(newVal) {
          console.log('newVal--newVal', newVal)

          this.pageData = Object.values(newVal)
        },
      },
    },
    mounted() {
      // 预览模式+api填写后再发请求
      // if (this.hasPreview && this.info.extension.api.value) {
      //   this.requestPageData()
      // }
      if (this.info.data && this.info.data.formData) {
        this.pageData = Object.values(this.info.data.formData)
        console.log('this.pageData', this.pageData)
      }
    },
    methods: {
      // requestPageData() {
      //   let requestDataObj = {}
      //   isArray(this.info.extension.requestData.value) &&
      //     this.info.extension.requestData.value.forEach((item) => {
      //       let itemVal = item.value
      //       if (/#{.*?}/g.test(item.value)) {
      //         itemVal = replaseRegVariable(itemVal, this.info)
      //       }
      //       requestDataObj[item.key] = processingConstant(this, itemVal)
      //     })
      //   let options = {
      //     api: this.info.extension.api.value,
      //     method: this.info.extension.method.value,
      //     getDataKey: this.info.extension.getDataKey.value,
      //     data: requestDataObj,
      //   }
      //   if (!trim(options.api)) return
      //   this.request(options)
      // },
      // 请求接口
      // request(options = {}) {
      //   this.loading = true
      //   let getDataKey = options.getDataKey
      //   //发起请求
      //   return request({
      //     url: GFCD('dams', 'domain') + options.api,
      //     method: 'post',
      //     data: {
      //       data: JSON.stringify(options.data),
      //       method: options.method,
      //     },
      //   }).then((res) => {
      //     this.loading = false
      //     this.pageData = isEmpty(getDataKey) ? res.data.data || [] : res.data[getDataKey].data || []
      //     console.log('铁头娃!!!!!!!!', this.pageData)
      //   })
      // },
      handleCurrentChange(val) {
        this.currentPage = val
        this.onClick()
      },
      //交给动作用的数据
      $getData() {
        return this.pageData[this.currentPage - 1]
      },
    },
  })
</script>
<style scoped>
  .ui-pagination {
    display: block;
  }
</style>
